#include "StdAfx.h"
#include "VoiceCardConfig.h"

CVoiceCardConfig::CVoiceCardConfig(void)
: m_ServerPort(0)
{
}

CVoiceCardConfig::~CVoiceCardConfig(void)
{
}

std::string CVoiceCardConfig::getConfigFileName(void)
{
	return getRootFolder()+std::string("\\TinyCC\\localhost\\CCVoiceCard.xml");
}

bool CVoiceCardConfig::readConfigFile(std::string filename)
{
	if(openXmlFile(filename) == false)
		return false;
	//read file in here
	try{
		xercesc::DOMNode *current2 = m_walker->getCurrentNode();
		//current2=walker->nextNode();
		std::string name(xercesc::XMLString::transcode(current2->getNodeName()));

		if(name=="CCVoiceCard")
		{

			for(current2=m_walker->nextNode();current2!=0;current2=m_walker->nextNode())
			{
				//read setting
				name = xercesc::XMLString::transcode(current2->getNodeName());
				if(name==std::string("Instance"))
				{
					current2=m_walker->nextNode();
					if(current2==0)
						break;
					name = xercesc::XMLString::transcode(current2->getNodeName());
					if(name == "Name")
						this->m_InstanceName = xercesc::XMLString::transcode(((xercesc::DOMElement*)current2)->getTextContent());

					current2=m_walker->nextNode();
					if(current2==0)
						break;
					name = xercesc::XMLString::transcode(current2->getNodeName());
					if(name == "ModuleIP")
						m_ModuleIP = xercesc::XMLString::transcode(((xercesc::DOMElement*)current2)->getTextContent());

					current2=m_walker->nextNode();
					if(current2==0)
						break;
					name = xercesc::XMLString::transcode(current2->getNodeName());
					if(name == "ModulePort")
						m_ModulePort = atoi(xercesc::XMLString::transcode(((xercesc::DOMElement*)current2)->getTextContent()));
					
					current2=m_walker->nextNode();
					if(current2==0)
						break;
					name = xercesc::XMLString::transcode(current2->getNodeName());
					if(name == "ServerIP")
						m_ServerIP = xercesc::XMLString::transcode(((xercesc::DOMElement*)current2)->getTextContent());

					current2=m_walker->nextNode();
					if(current2==0)
						break;
					name = xercesc::XMLString::transcode(current2->getNodeName());
					if(name == "ServerPort")
						m_ServerPort = atoi(xercesc::XMLString::transcode(((xercesc::DOMElement*)current2)->getTextContent()));


				}

				name = xercesc::XMLString::transcode(current2->getNodeName());
				if(name==std::string("Hardware"))
				{
					current2=m_walker->nextNode();
					if(current2==0)
						break;
					name = xercesc::XMLString::transcode(current2->getNodeName());
					if(name == "CardType")
						this->m_CardType = xercesc::XMLString::transcode(((xercesc::DOMElement*)current2)->getTextContent());
				}
			}
		}

	}
	catch(...)
	{
		//		strTime = CTime::GetCurrentTime().Format("%Y-%m-%d-%a  %H:%M:%S"); 
		//MessageBox ("Parse xml file Error");
		closeXmLFile();
		return false;
	}
	//end read 
	closeXmLFile();

	return true;
}